# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
	# @param {ListNode} head
	# @param {integer} val
	# @return {ListNode}
	def removeElements(self, head, val):
		H = ListNode(None)
		H.next = head
		pre = H
		while head:
			if head.val == val:
				pre.next = head.next
			else:
				pre = pre.next
			head = head.next
		return H.next


if __name__ == '__main__':
	head = ListNode(None)
	h = head
	for i in []:
		h.next = ListNode(i)
		h = h.next

	H = Solution().removeElements(head.next, 4)
	while H:
		print H.val,
		H = H.next
